package com.dayatang.koala.support;

import java.io.Reader;
import java.util.Map;

import javax.rules.admin.LocalRuleExecutionSetProvider;
import javax.rules.admin.RuleExecutionSet;

import com.dayatang.koala.service.UnSupportRuleFormatException;

public class RuleExecutionSetReaderCreator implements RuleExecutionSetCreator {

	public RuleExecutionSet createRuleExecutionSet(Object ruleSource,
			Map ruleProperty,
			LocalRuleExecutionSetProvider ruleExecutionSetProvider)
			throws RuntimeException {
		try {
			if (ruleSource instanceof Reader) {
				return ruleExecutionSetProvider.createRuleExecutionSet(
						(Reader) ruleSource, ruleProperty);
			} else {
				throw new UnSupportRuleFormatException();
			}
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

}
